package gazpachito.examples.patterns.methodTemplate.business.vehicle;

import gazpachito.examples.patterns.methodTemplate.api.AnimalVehicleDTO;
import gazpachito.examples.patterns.methodTemplate.api.VehicleDTO;
import gazpachito.examples.patterns.methodTemplate.business.exceptions.BusinessException;
import gazpachito.examples.patterns.methodTemplate.utils.MessageUtils;

import org.springframework.stereotype.Component;

/**
 * This abstract class contains all the business rules are commons for all the
 * different kinds of vehicles.
 * 
 * @author jvillar
 * 
 */
@Component("AnimalVehicleBusiness")
public class AnimalVehicleBusinessImpl extends
		AbstractVehicleBusinessImpl<AnimalVehicleDTO> {

	@Override
	public void validateConcrete(VehicleDTO vehicle) throws BusinessException {
		// TODO Auto-generated method stub
		AnimalVehicleDTO animal = (AnimalVehicleDTO) vehicle;

		if (animal.getKindVehicle() == null) {
			throw new BusinessException(
					MessageUtils
							.getMessage(MessageUtils.ERROR_ANIMAL_NOT_INFORMED));
		}

	}

	@Override
	public void executeConcrete(VehicleDTO vehicle) {
		AnimalVehicleDTO animal = (AnimalVehicleDTO) vehicle;
		super.getStoredVehicles().put(animal.getIdVehicle(), animal);

	}

}
